<?php
if (!defined('BASEPATH'))
	exit('No direct script access allow');

class Setting extends  admin_controller {
	public function __construct() {
		parent::__construct();

		$this -> check_login();
		//$this -> permission_view('setting');
		//$this -> load -> model('setting/setting_model', 'setting');
		//$this->load->model('language/site_lang_model', 'm_lang');
	}

	public function index() {
		$act = $this -> input -> post('h_act');
		//$oldLogo = $this -> input -> post('oldLogo');
		//$oldBaogia = $this -> input -> post('oldbaogia');

		if ($act == 'do_action') {

			/*
			$config['upload_path'] = './' . $this -> config -> item('upload_image');
			$config['allowed_types'] = 'gif|jpg|png|doc|xls';
			$config['encrypt_name'] = TRUE;

			if (!empty($_FILES['logo_url']['name'])) {

				$this -> load -> library('upload', $config);

				if (!$this -> upload -> do_upload('logo_url')) {
					$logo_url = $oldLogo;
				} else {
					$up = $this -> upload -> data();
					$logo_url = $this -> config -> item('upload_image') . $up['file_name'];

					$imageWidth = $up['image_width'];
					if ($imageWidth > 328) {
						$this -> load -> library('image_lib');
						$config['image_library'] = 'GD2';
						$config['source_image'] = $up['full_path'];
						$config['quality'] = 75;
						$config['maintain_ratio'] = TRUE;
						$config['master_dim'] = 'auto';
						$config['width'] = 328;
						$config['height'] = 78;

						$this -> image_lib -> initialize($config);
						$this -> image_lib -> resize();
					}

					@unlink($oldLogo);
				}
			} else {
				$logo_url = $oldLogo;
			}*/

			//$this -> db -> where('option_key', 'logo_url');
			//$this -> db -> set('option_value', $logo_url);
			//$this -> db -> update('options');

			//$this -> db -> where('option_key', 'bao_gia');
			//$this -> db -> set('option_value', $baogia);
			//$this -> db -> update('options');

			foreach ($_POST as $key => $val) {
				//Update table config_system
				$this -> db -> where('key', $key);
				$this -> db -> set('value', $val);
				$this -> db -> update('config_site');

			}
			//print_r($_POST);
			$this -> message('info', t_lang('update_success'));
			//redirect(URL_ADMIN . 'setting');

		}

		//$listLang = $this->m_lang->getAll(array('lang_code', 'lang_name'), null, null, null);

		$txt = array('action_form' => URL_ADMIN . 'setting');

		$this -> template -> title('Cấu hình hệ thống')
		-> set('link_action', URL_ADMIN .'setting/index')
		-> build('admin/setting/index');
	}

}

// End class
